package com.gxc.service.impl;

import com.gxc.dao.jpa.UserRepository;
import com.gxc.entity.User;
import com.gxc.service.UserService;
import java.util.List;
import javax.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

/**
 * UserServiceImpl.
 *
 * @author 宫新程
 * @since 2018/12/15 2:12 PM
 */
@Slf4j
@Service
public class UserServiceImpl implements UserService {

  public UserServiceImpl() {
    System.out.println("UserServiceImpl....初始化成功!");
  }

  @Resource private UserRepository userRepository;

  /** 根据用户名查询用户信息. */
  @Override
  public List<User> findUserByUsername(String username) {
    return userRepository.findByUsername(username);
  }

  /** 查询所有. */
  @Override
  public Page<User> findAll(Integer pageNum, Integer pageSize) {
    Pageable pageable = PageRequest.of(pageNum - 1, pageSize);
    return userRepository.findAll(pageable);
  }
}
